class_name BaseRoad
extends Node2D

enum RoadDirection
{
	Up,
	Right,
	Down,
	Left,
}
#region 属性
@export var direction:RoadDirection
@export var road:TileMapLayer
@export var not_road:TileMapLayer
@export var door:TileMapLayer
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
#endregion
#region 公共方法
func init(road_length:int = 1):
	for i in range(2,road_length + 1):
		copy_tiles_in_direction(road,Constant.FOUR_DIR_OFFEST[direction],i - 1)
# 复制tile到指定方向
func copy_tiles_in_direction(tilemap_layer:TileMapLayer ,direction: Vector2i, distance: int = 1):
	# 获取所有已使用的tile位置
	var used_cells = tilemap_layer.get_used_cells()
	var cells_to_add = []
	
	# 计算每个tile的新位置
	for cell_position in used_cells:
		var new_position = cell_position + (direction * distance)
		
		# 获取原tile的所有信息
		var source_id = tilemap_layer.get_cell_source_id(cell_position)
		var atlas_coords = tilemap_layer.get_cell_atlas_coords(cell_position)
		var alternative_tile = tilemap_layer.get_cell_alternative_tile(cell_position)
		
		# 存储要添加的tile信息
		cells_to_add.append({
			"position": new_position,
			"source_id": source_id,
			"atlas_coords": atlas_coords,
			"alternative_tile": alternative_tile
		})
	
	# 批量设置新tile
	for cell_data in cells_to_add:
		tilemap_layer.set_cell(
			cell_data.position,
			cell_data.source_id,
			cell_data.atlas_coords,
			cell_data.alternative_tile
		)
#endregion
#region 私有方法
#endregion
#region 生命周期函数
#endregion
